#ifndef POPUPCONNECTIONACK_HPP_
#define POPUPCONNECTIONACK_HPP_

#include <PopupLibTypes.hpp>
#include "PopupAbstractMessage.hpp"

namespace Popup
{
  struct ConnectionAck : public AbstractMessage
  {
    enum
    {
      STATUS,
      ERR_MESSAGE,
      SESSIONID,
      USERID,
      USERNICKNAME,
      AVATAR_RAW_DATA,
      AVATAR_FILENAME,
      HEALTH
    };

    //! Constructor used in order to send a connection NACK
    ConnectionAck(ConnectionEcode p_status,
                  const std::string & p_message = "Blurp!") :
      AbstractMessage(POPUP_MSG_TYPE_CONNECTION_ACK),
      status(p_status), errMessage(p_message) {}

    //! Constructor used in order to send a connection ACK
    ConnectionAck(SessionID p_sessionID, const User & p_user) :
      AbstractMessage(POPUP_MSG_TYPE_CONNECTION_ACK),
      status(POPUP_CONNECTION_SUCCESS), errMessage("Success"),
      sessionID(p_sessionID), user(p_user) {}

    //! Constructor used in order to received a login request
    ConnectionAck(const Message *p_message,
                       const std::string & p_resourcePath = ".");

    ~ConnectionAck() {}

    //!@Override
    bool onSend();

    //!@Override
    bool onReceive();

    inline ConnectionEcode getStatus() const {
      return (ConnectionEcode) status;
    }
    inline const std::string & getErrMessage() const {
      return errMessage;
    }
    inline const User & getUser() const {
      return user;
    }
    inline SessionID getSessionID() const {
      return sessionID;
    }

  private:
    unsigned short status;
    std::string errMessage;
    SessionID sessionID;
    User user;
    std::string resourcePath;
  };
}

#endif /* POPUPCONNECTIONACK_HPP_ */
